package com.trtan.hr.controller.system;

import com.alibaba.fastjson.JSONObject;
import com.trtan.hr.pojo.RespBean;
import com.trtan.hr.pojo.RespPageEntity;
import com.trtan.hr.service.IconService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: trtan
 * @create: 2021-05-06 20:56
 * @description: 图标
 **/
@RestController
@RequestMapping("/system/icon")
public class IconController {
    Logger logger = LoggerFactory.getLogger(HrController.class);
    @Autowired
    IconService iconService;

    @RequestMapping("/allICons")
    public RespBean getAllRoles(@RequestBody JSONObject params) {
        logger.info(params.toString());
        Integer currentPage = params.getInteger("currentPage");
        Integer pageSize = params.getInteger("pageSize");
        RespBean respBean;
        try {
            RespPageEntity entity = iconService.selectAll(currentPage, pageSize);
            respBean = RespBean.ok("", entity);
        } catch (Exception e) {
            e.printStackTrace();
            respBean = RespBean.error("服务器错误，请联系管理员！");
        }
        return respBean;
    }

    @RequestMapping("/refresh")
    public RespBean refresh() {
        RespBean respBean;
        try {
            iconService.addIcons();
            respBean = RespBean.ok("重新获取成功!");
        } catch (Exception e) {
            e.printStackTrace();
            respBean = RespBean.error("服务器错误，请联系管理员！");
        }
        return respBean;
    }
}
